﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：吕海乐 
    //
    // 文件名：MessageInfo.aspx.cs
    // 文件功能描述：消息管理：消息详细信息
    // 创建标识：吕海乐2009-5-20
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.Model;

namespace HZ.DrugTrade.Web.Hospitals.MessageManage
{
    public partial class NoteInfo : BasePage
    {

        /// <summary>
        /// 消息的类别
        /// </summary>
        public string MSGType { get; set; }

        public NoteInfo()
        {
            this.ModuleNo = "";
        }

        IBLL_Message im = Factory.BLL_Message();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                BindInfo();
            }
        }

        /// <summary>
        /// 绑定公告的详细信息
        /// </summary>
        private void BindInfo()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["flag"]) && !string.IsNullOrEmpty(Request.QueryString["mID"]))
            {
                int temp;
                //获取公告类别（N1：已接收的公告；N2：待审核的公告；N3:已发布的公告）
                string flag = Request.QueryString["flag"];
                string id = Request.QueryString["mID"];
                hdfID.Value = id;


                if (flag == "N1")
                {
                    MSGType = "已接收";
                    Model.View.Notice aNotice = im.GetRecievedNotice(new HZ.DrugTrade.Model.Query.Notice() { NoticeSerialID = id }, 1, 0, out temp)[0];
                    lblTitle.Text = aNotice.Title;
                    txtContent.Visible = false;
                    txtTitle.Visible = false;
                    tdReciever.InnerText = aNotice.RoleNames;
                    tdSender.InnerText = aNotice.SenderName;
                    tdSendTime.InnerText = aNotice.SendTime.ToString();
                    ltrContent.Text = aNotice.NoticeContent;
                    hdfReciever.Value = aNotice.Reciever;
                    hdfSender.Value = aNotice.Sender;
                }
                else if (flag == "N2")
                {
                    MSGType = "待审核";
                    btnAudit.Visible = true;
                    btnDel.Visible = true;
                    lblTitle.Visible = false;
                    ltrContent.Visible = false;
                    Model.View.Notice aNotice = im.GetAuditNotice(new HZ.DrugTrade.Model.Query.Notice() { NoticeSerialID = id }, 1, 0, out temp)[0];
                    txtTitle.Text = aNotice.Title;
                    tdReciever.InnerText = aNotice.RoleNames;
                    tdSender.InnerText = aNotice.SenderName;
                    tdSendTime.InnerText = aNotice.SendTime.ToString();
                    txtContent.Value = aNotice.NoticeContent;
                    hdfReciever.Value = aNotice.Reciever;
                    hdfSender.Value = aNotice.Sender;

                }
                else if (flag == "N3")
                {
                    MSGType = "已发布";
                    btnAudit.Visible = true;
                    btnNoAudit.Visible = true;
                    btnDel.Visible = true;
                    lblTitle.Visible = false;
                    ltrContent.Visible = false;
                    Model.View.Notice aNotice = im.GetNotice(new HZ.DrugTrade.Model.Query.Notice() { NoticeSerialID = id }, 1, 0, out temp)[0];
                    txtTitle.Text = aNotice.Title;
                    tdReciever.InnerText = aNotice.RoleNames;
                    tdSender.InnerText = aNotice.SenderName;
                    tdSendTime.InnerText = aNotice.SendTime.ToString();
                    txtContent.Value = aNotice.NoticeContent;
                    hdfReciever.Value = aNotice.Reciever;
                    hdfSender.Value = aNotice.Sender;
                }
            }
            else
            {
                PageError("数据已经不存在，请先选择相应的公告！", this.ReturnUrl);
            }
        }


        /// <summary>
        ///修改并审核公告
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAudit_Click(object sender, EventArgs e)
        {
            Notice aNotice = new Notice();
            aNotice.NoticeSerialID = hdfID.Value;
            aNotice.AuditStatus = true;
            aNotice.AuditUser = CurrentAccount.GetUser().UserID;
            aNotice.NoticeContent = txtContent.Value;
            aNotice.Title = txtTitle.Text;

            int flag = im.UpdateNotice_Audit(aNotice);
            if (flag == 1)
            {
                PageInfo("操作成功！", "AuditNoticeList.aspx");
            }
            else
            {
                PageError("操作失败！", this.ReturnUrl);
            }
        }

        /// <summary>
        ///修改并审核不通过公告
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnNoAudit_Click(object sender, EventArgs e)
        {
            Notice aNotice = new Notice();
            aNotice.NoticeSerialID = hdfID.Value;
            aNotice.AuditStatus = false;
            aNotice.AuditUser = CurrentAccount.GetUser().UserID;
            aNotice.NoticeContent = txtContent.Value;
            aNotice.Title = txtTitle.Text;
            int flag = im.UpdateNotice_Audit(aNotice);
            if (flag == 1)
            {
                PageInfo("操作成功！", "AuditNoticeList.aspx");
            }
            else
            {
                PageError("操作失败！", this.ReturnUrl);
            }
        }


        /// <summary>
        /// 删除公告
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDel_Click(object sender, EventArgs e)
        {
            IList<Notice> lstNotice = new List<Notice>();
            lstNotice.Add(new Notice() { NoticeSerialID = hdfID.Value });
            int flag = im.DeleteNotice_Batch(lstNotice);
            if (flag == 1)
            {
                PageInfo("删除成功！", "AuditNoticeList.aspx");
            }
            else
            {
                PageError("删除失败！", this.ReturnUrl);
            }

        }
    }
}
